package com.gjy.rocketmq.config;

import com.gjy.rocketmq.properties.RocketMqYaml;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.MQPushConsumer;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.MQProducer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-09-14 09:30:37
 */
@Configuration
public class RocketMqConfig {
    @Resource
    public RocketMqYaml rocketMqYaml;

    @Bean
    public MQProducer producer() {
        DefaultMQProducer producer = new DefaultMQProducer(rocketMqYaml.getProducerGroup());
        producer.setNamesrvAddr(rocketMqYaml.getAddress());
        return producer;
    }

    @Bean
    public MQPushConsumer consumer() {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(rocketMqYaml.getConsumerGroup());
        consumer.setNamesrvAddr(rocketMqYaml.getAddress());
        return consumer;
    }
}
